package com.doctor.windflower_doctor.recordfragment;

import java.util.List;

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;

import com.doctor.windflower_doctor.R;
import com.doctor.windflower_doctor.SystemApplication;
import com.doctor.windflower_doctor.adapter.StatisticalListAdapter;
import com.doctor.windflower_doctor.entity.Notes;
import com.doctor.windflower_doctor.entity.RecordBeen;
import com.doctor.windflower_doctor.fragment.BaseFragment;
import com.doctor.windflower_doctor.http.parser.impl.JsonHelper;
import com.doctor.windflower_doctor.myuser.tools.HttpclientHelper;
import com.doctor.windflower_doctor.util.Constent;

public class WeightRecordFragment extends BaseFragment implements Constent {
	private static WeightRecordFragment baseFragment;
	private ListView listView;
	private StatisticalListAdapter statisticalListAdapter;
	private int type = 1;
	private List<RecordBeen> recordList;

	public static WeightRecordFragment getInstance(Bundle bundle) {
		baseFragment = new WeightRecordFragment();
		baseFragment.setArguments(bundle);
		return baseFragment;
	}

	@Override
	protected View setConentView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return inflater.inflate(R.layout.fragment_weight_record, container,
				false);
	}

	@Override
	protected void getSaveData(Bundle savedInstanceState) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void processLogic() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void setListener() {

	}

	@Override
	protected void findViews(View view) {
		listView = (ListView) view.findViewById(R.id.listView);
		listView.setDividerHeight(0);
		statisticalListAdapter = new StatisticalListAdapter(getActivity(), type);

		new WeightAsynck().execute(RECORD_URL_ONLINE+WEIGHT+SystemApplication.getInstance().doctorId);

	}

	@Override
	public void onResume() {
	
		super.onResume();
	}

	@Override
	public void onDestroyView() {
		baseFragment = null;
		super.onDestroyView();

	}

	@Override
	public void onStop() {
		baseFragment = null;
		super.onStop();

	}

	class WeightAsynck extends AsyncTask<String, Void, String> {

		@Override
		protected String doInBackground(String... params) {
			// TODO Auto-generated method stub
			return HttpclientHelper.getAddress(params[0]);
		}

		@Override
		protected void onPostExecute(String result) {
			// TODO Auto-generated method stub
			super.onPostExecute(result);
			if (result != null) {
				recordList = JsonHelper.record_Json(result);
				statisticalListAdapter.addListData(recordList);
				listView.setAdapter(statisticalListAdapter);

			} else {
				Toast.makeText(getActivity(), "请检查网络连接", Toast.LENGTH_SHORT)
						.show();
			}

		}
	}
}
